<?php
/**
 * Created by PhpStorm.
 * User: 明哲
 * Date: 2016/6/6
 * Time: 16:14
 */
include('../../config.php');

$action = $_GET['action'];
$id = $_GET['id'];

switch ($action) {
    default:
        $row = $mysql->query("select *  from `pipe` where `id`='{$id}'");
        if($row){
            echo json_encode($row[0],true);
        }else{
            echo 0;
        };
        break;
    case 'del' :
        $rows = $mysql->query("delete from `pipe` where `id`='{$id}'");
        echo 1;
        break;
    case 'update' :
        $pipe_name = $_GET['pipe_name'];
        $pipe_type = $_GET['pipe_type']=='cpa'? '0' : '1' ;
        $unit_price = $_GET['unit_price'];
        $clear_cycle = $_GET['clear_cycle'];
        $product_name = $_GET['product_name'];
        $pipe_username = $_GET['pipe_username'];
        $pipe_pass = $_GET['pipe_pass'];
        $rows = $mysql->query("update `pipe` set `pipe_name`='{$pipe_name}',`pipe_type`='{$pipe_type}',`unit_price`='{$unit_price}',`clear_cycle`='{$clear_cycle}',`product_name`='{$product_name}',`pipe_username`='{$pipe_username}',`pipe_pass`='{$pipe_pass}' where `id`='{$id}'");
        if(!$rows){
            echo 1;
        }else{
            echo 0;
        }
        break;

}
